#include <bits/stdc++.h>
using namespace std;

using ll = int64_t;
const int N = 2e5 + 10;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    int a[N];
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    ll ret = -1e6, sum = 0;
    
    for(int i = 1; i <= n; ++i){
        sum += a[i];
        ret = max(ret, sum);
        if(sum < 0) sum = 0;
    }
    cout << ret << '\n';
    return 0;
}